




use "C:\Users\Kevin\Dropbox\UCR\research\bayes\funglee\persuasion\persuasion_v12.dta"

* first create the "H" variables for the means of pretreatment responses within a table, not including the participant's own response...
capture drop x
bysort sitetable: egen x = mean(oboe_PR_DEF_TAXRICH)
gen Htaxrich= (x*tcount - oboe_PR_DEF_TAXRICH)/(tcount - 1)

capture drop x
bysort sitetable: egen x = mean(oboe_PR_DEF_CUTPROG)
gen Hcutprog= (x*tcount - oboe_PR_DEF_CUTPROG)/(tcount - 1)

capture drop x
bysort sitetable: egen x = mean(oboe_PR_DEF_TAXBOTH)
gen Htaxboth= (x*tcount - oboe_PR_DEF_TAXBOTH)/(tcount - 1)

capture drop x
bysort sitetable: egen x = mean(oboe_PR_DEF_ENTITLE)
gen Hentitle= (x*tcount - oboe_PR_DEF_ENTITLE)/(tcount - 1)

capture drop x
bysort sitetable: egen x = mean(oboe_PR_DEF_DEFENSE)
gen Hdefense= (x*tcount - oboe_PR_DEF_DEFENSE)/(tcount - 1)

capture drop x
bysort sitetable: egen x = mean(oboe_PR_DEF_FEDSALES)
gen Hfedsales= (x*tcount - oboe_PR_DEF_FEDSALES)/(tcount - 1)


polychoric oboe_PR_DEF_TAXRICH oboe_PR_DEF_CUTPROG oboe_PR_DEF_ENTITLE oboe_PR_DEF_DEFENSE
polyfactor /* polyfactor is just a wrapper for doing the Stata factor procedure using the above polychoric correlation matrix. */
predict latent_pre
polychoric oboe_PT_DEF_TAXRICH oboe_PT_DEF_CUTPROG oboe_PT_DEF_ENTITLE oboe_PT_DEF_DEFENSE
polyfactor
predict latent_post


capture drop x
bysort sitetable: egen x = mean(latent_pre)
gen Hlatent= (x*tcount - latent_pre)/(tcount - 1)
gen Hlatent2 = Hlatent*Hlatent
gen Hlatent2xl = Hlatent2*liberal
gen Hlatent2xc = Hlatent2*conservative


drop x

* the variable ideologyx is contained in the loaded data file (and in persuasion_v12.dta) and is constructed from
* egen ideologyx=std(latent_pre), -- you can see latent_pre constructed as a factor score in PersuasionFarrarAnalysis.do
gen conservative=ideologyx>.3438691
replace conservative=. if ideologyx==.
gen liberal=ideologyx<-.5483488
replace liberal=. if ideologyx==.

* The original Farrar et al specification
ologit oboe_PT_DEF_TAXRICH i.oboe_PR_DEF_TAXRICH Htaxrich i.site, cluster(sitetable)
ologit oboe_PT_DEF_CUTPROG i.oboe_PR_DEF_CUTPROG Hcutprog i.site, cluster(sitetable)
ologit oboe_PT_DEF_TAXBOTH i.oboe_PR_DEF_TAXBOTH Htaxboth i.site, cluster(sitetable)
ologit oboe_PT_DEF_ENTITLE i.oboe_PR_DEF_ENTITLE Hentitle i.site, cluster(sitetable)
ologit oboe_PT_DEF_DEFENSE i.oboe_PR_DEF_DEFENSE Hdefense i.site, cluster(sitetable)
ologit oboe_PT_DEF_FEDSALES i.oboe_PR_DEF_FEDSALES Hfedsales i.site, cluster(sitetable)
reg latent_post latent_pre Hlatent i.site, cluster(sitetable)

* testing for law of small group polarization
reg latent_post latent_pre Hlatent Hlatent2 Hlatent2xl Hlatent2xc liberal conservative i.site, cluster(sitetable)






